package com.fly.service;

import com.fly.domain.model.CustomerCashInfo;
import com.fly.domain.model.CustomerFeedbackInfo;
import com.fly.domain.model.CustomerOfferInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.stereotype.Service;

/**
 * @author frinder
 * @date 2018/5/19
 * @className MyCustomerService
 * @package com.fly.service
 * @Description: ${todo}
 */
@Service
public class MyCustomerService {

    @Autowired
    private MyJdbcService myJdbcService;

    /**
     * 查询 customerSid 最近一次充值记录
     *
     * @param customerSid
     * @return
     */
    public CustomerCashInfo getLastCashInfo(String customerSid) {
        String sql = "SELECT *\n" +
                "FROM customer_cash_info t\n" +
                "WHERE t.customer_sid = (:customerSid)\n" +
                "ORDER BY t.id DESC\n" +
                "LIMIT 1";
        MapSqlParameterSource queryParameterSource = new MapSqlParameterSource("customerSid", customerSid);
        return myJdbcService.queryOne(CustomerCashInfo.class, sql, queryParameterSource);
    }

    /**
     * 查询 customerSid 最近一次邀约记录
     *
     * @param customerSid
     * @return
     */
    public CustomerOfferInfo getLastOfferInfo(String customerSid) {
        String sql = "SELECT *\n" +
                "FROM customer_offer_info t\n" +
                "WHERE t.customer_sid = (:customerSid)\n" +
                "ORDER BY t.id DESC\n" +
                "LIMIT 1";
        MapSqlParameterSource queryParameterSource = new MapSqlParameterSource("customerSid", customerSid);
        return myJdbcService.queryOne(CustomerOfferInfo.class, sql, queryParameterSource);
    }

    /**
     * 查询 customerSid 最近一次反馈记录
     *
     * @param customerSid
     * @return
     */
    public CustomerFeedbackInfo getLastFeedbackInfo(String customerSid) {
        String sql = "SELECT *\n" +
                "FROM customer_feedback_info t\n" +
                "WHERE t.customer_sid = (:customerSid)\n" +
                "ORDER BY t.id DESC\n" +
                "LIMIT 1";
        MapSqlParameterSource queryParameterSource = new MapSqlParameterSource("customerSid", customerSid);
        return myJdbcService.queryOne(CustomerFeedbackInfo.class, sql, queryParameterSource);
    }

}
